package org.lq.er.util;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {

	/**
	 * 时间转datetime类型
	 * @param date 年月日
	 * @param strDate 时分秒的字符串表示
	 * @return 
	 */
	public static Date myFormat(Date date, String strDate) {
		SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date strtodate = formatter.parse(strDate, new ParsePosition(0));
		String sd = sdf.format(new Date(date.getTime()+strtodate.getTime()+8*60*60*1000));
		Date dt = sdf.parse(sd, new ParsePosition(0));
		return dt;
	}
	
	public static Date getDate(String strDate) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date strtodate = formatter.parse(strDate, new ParsePosition(0));
		return strtodate;
	}

	public static String toStr(Date date) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dateString = formatter.format(date);
		return dateString;
	}

	public static String toDate(Date date) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		String dateString = formatter.format(date);
		return dateString;
	}
	
	public static String toTime(Date date) {
		SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
		String dateString = formatter.format(date);
		return dateString;
	}

	public static String timeOperation(Date date, int min) {
		SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
		String dateString = formatter.format(new Date(date.getTime()+min*60*1000));
		return dateString;
	}
}
